<?php
	require_once('../inc/fen_fns.php');

	sec_session_start();
	$pid = $_GET['pid'];
	
	if (login_check($mysqli, '>', '10') == true) {

		if ($_SESSION['access_level'] >= 60) {
			$query = $_DB->Query("SELECT
							fen_transaction_history.id as id,
							fen_transaction_history.added_by as added_by,
							date_FORMAT(fen_transaction_history.date_added , '%d/%m/%Y %H:%i') as date_added,
							fen_transaction_history.status as status,
							fen_transaction_history.ip as ip,
							fen_publications.eser_adi as eser_adi,
							fen_publications.id as publication_id
							from fen_transaction_history, fen_publications
							WHERE
							fen_transaction_history.publication_id = '".$pid."' and
							fen_transaction_history.publication_id = fen_publications.id
							");
		} else if ($_SESSION['access_level'] >= 50) {
			$query = $_DB->Query("SELECT
							fen_transaction_history.id as id,
							fen_transaction_history.added_by as added_by,
							date_FORMAT(fen_transaction_history.date_added , '%d/%m/%Y %H:%i') as date_added,
							fen_transaction_history.status as status,
							fen_transaction_history.ip as ip,
							fen_publications.eser_adi as eser_adi,
							fen_publications.id as publication_id
							from fen_transaction_history, fen_publications, fen_members
							WHERE
							fen_transaction_history.publication_id = '".$pid."' and
							fen_transaction_history.publication_id = fen_publications.id and
							fen_publications.member_id = fen_members.id and
							fen_members.faculty_id = (select faculty_id from fen_members where id = '".$_SESSION['user_id']."')
							");
		} else {
			$query = $_DB->Query("SELECT
							fen_transaction_history.id as id,
							fen_transaction_history.added_by as added_by,
							date_FORMAT(fen_transaction_history.date_added , '%d/%m/%Y %H:%i') as date_added,
							fen_transaction_history.status as status,
							fen_transaction_history.ip as ip,
							fen_publications.eser_adi as eser_adi,
							fen_publications.id as publication_id
							from fen_transaction_history, fen_publications
							WHERE
							fen_transaction_history.publication_id = '".$pid."' and
							fen_transaction_history.publication_id = fen_publications.id and
							fen_publications.member_id = '".$_SESSION['user_id']."'
							");
		}
		
		$count = $_DB->GetResultNumber($query);
		
		$querystatus = $_DB->Query("SELECT status from fen_publication_app where publication_id = '".$pid."'");

		
				
?>

	<script type="text/javascript">
	
	function cancelReason(obj) {  
	
		jQuery(document).ready(function($) {
			  $('a[rel*=facebox]').facebox() 
	
			  jQuery.facebox({ ajax: 'applications/application-cancel.php?pid='+obj })
		}) 
	} 

	</script>

	<div id="user_detailed_div">
	<div id="user_detailed_head_div">
	<p id="user_detailed_name">&nbsp;
	İşlem Tarihçesi
	</p>
	</div>
	
	
	
	
	<div class="summaryTableSmall2detailed2">

	<table id="appDetailedTable">
		<tr>
			<td id="appDetailedTD3">Eser Adı:</td>
			<td id="appDetailedTD3b"><?php echo $_DB->GetResultValue($query, "0", "eser_adi"); ?></b></td>
		</tr>
	</table>
	
	<img src="images/process/line.gif"></img>
	<br><br>
	<center><img src="images/process/0<?php if (strlen($_DB->GetResultValue($querystatus, "0", "status")) > 0) { echo $_DB->GetResultValue($querystatus, "0", "status"); } else { echo "1"; } ?>.gif"></img></center>
	<br>
	<table width="450" align="center">
		<tr>
			<td id="thistorytd<?php if ($_DB->GetResultValue($querystatus, "0", "status") == '1') { echo "now"; } else { echo ""; } ?>">Kaydedildi</td>
			<td id="thistorytd<?php if ($_DB->GetResultValue($querystatus, "0", "status") == '2') { echo "now"; } else if ($_DB->GetResultValue($querystatus, "0", "status") == '0') { echo "cancelled"; } else if ($_DB->GetResultValue($querystatus, "0", "status") > 2) { echo ""; } else { echo "disabled"; } ?>">Yayın Komisyonu</td>
			<td id="thistorytd<?php if ($_DB->GetResultValue($querystatus, "0", "status") == '3') { echo "now"; } else if ($_DB->GetResultValue($querystatus, "0", "status") > 3) { echo ""; } else { echo "disabled"; } ?>">Rektörlük</td>
			<td id="thistorytd<?php if ($_DB->GetResultValue($querystatus, "0", "status") == '4') { echo "now"; } else if ($_DB->GetResultValue($querystatus, "0", "status") > 4) { echo ""; } else { echo "disabled"; } ?>">Mali İşler</td>
			<td id="thistorytd<?php if ($_DB->GetResultValue($querystatus, "0", "status") == '5') { echo "now"; } else if ($_DB->GetResultValue($querystatus, "0", "status") > 5) { echo ""; } else { echo "disabled"; } ?>">Ödeme Yapıldı</td>
		</tr>
	</table>
	
	<br><br>
	<table cellspacing="0" cellpadding="0" class="summaryTableMakale">
		<tr id="summaryTableMakaleRowTopDetailed">
			<td>&nbsp;#</td>
			<td id="summaryTableMakaleDepartmentsTDblue">İşlem</td>
			<td>IP Adresi</td>
			<td>Tarih</td>
			<td id="summaryTableMakaleDepartmentsTDblue">İşlemi Yapan</td>
		</tr>
<?php 
		
		for ($i=0; $i<$count; $i++) {
		
			$no = $i + 1;
			
			if ($_DB->GetResultValue($query, $i, "status") == 'Rektörlüğe Gönderildi.') {
				$status = "<font color=\"#539e3b\">Rektörlüğe Gönderildi.</font>";
			} else if ($_DB->GetResultValue($query, $i, "status") == 'Reddedildi.') {
				$status = "<font color=\"#dd0303\">Reddedildi.</font>";
			} else if ($_DB->GetResultValue($query, $i, "status") == 'Mali İşlere Gönderildi.') {
				$status = "<font color=\"#8066a0\">Mali İşlere Gönderildi.</font>";
			} else if ($_DB->GetResultValue($query, $i, "status") == 'Ödeme Yapıldı.') {
				$status = "<font color=\"#35aed5\">Ödeme Yapıldı.</font>";
			} else {
				$status = $_DB->GetResultValue($query, $i, "status");
			}
			
			echo "
				<tr id=\"summaryTableBolumRow1detail\">
					<td>&nbsp;".$no."</td>
					<td align=\"left\">&nbsp;&nbsp;".$status."</td>
					<td align=\"left\">".$_DB->GetResultValue($query, $i, "ip")."</td>
					<td align=\"left\">".$_DB->GetResultValue($query, $i, "date_added")."</td>								
					<td align=\"left\">".$_DB->GetResultValue($query, $i, "added_by")."</td>
				</tr>
			";
		}

?>
						
	</div>
	
<?php 

	} else {
		header('Location: ./index.php?error=2');
	}

?>